package com.heima.kafka.boot.controller;

import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 生产者类
 */
@RestController
@RequestMapping("/producer")
public class ProducerController {

    @Autowired
    private KafkaTemplate<String,String> kafkaTemplate;

    @GetMapping("/send")
    public  String sendMessage(){
       /* Map map=new HashMap();
        map.put("name","二狗子");
        map.put("sex","男");
        map.put("age",13);*/
        for (int i = 0; i <5 ; i++) {
            if(i%2==0){
                kafkaTemplate.send("stream-send-topic", "hello kitty");
            }else{
                kafkaTemplate.send("stream-send-topic", "hello monkey");
            }
        }

        return "发送成功";
    }
}
